package de.koller.oceanFramework.gl.util;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class ImagePreview {

	private ImagePreview() {}
	
	public static void showRaster( IImageRaster raster, int width, int height ) {
		BufferedImage bi = new BufferedImage( raster.getWidth(), raster.getHeight(), BufferedImage.TYPE_INT_ARGB );
		for( int x = 0; x < bi.getWidth(); x++ )
			for( int y = 0; y < bi.getHeight(); y++ ) 
				bi.setRGB( x, y, raster.getColor( x, y ) );
		showImage( bi, width, height );
	}
	
	public static void showImage( BufferedImage image, int width, int height ) {
		JOptionPane.showMessageDialog( null, new IP( image, width, height ), "", JOptionPane.PLAIN_MESSAGE, null );
	}
	
	private static class IP extends JPanel {
		private final BufferedImage bi;
		private final int width, height;
		
		public IP( BufferedImage bi, int width, int height ) {
			this.bi = bi;
			this.setPreferredSize( new Dimension( width, height ) );
			this.width = width;
			this.height = height;
		}

		@Override
		protected void paintComponent( Graphics g ) {
			super.paintComponent( g );
		
			g.drawImage( bi, 0, 0, width, height, null );
		}
		
	}
	
}
